package logic

import (
	"context"
	"teatch/model/mysql"

	"teatch/teacherrpc/internal/svc"
	"teatch/teacherrpc/teacherrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type EvaluateListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewEvaluateListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EvaluateListLogic {
	return &EvaluateListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论列表
func (l *EvaluateListLogic) EvaluateList(in *teacherrpc.EvaluateListRequest) (*teacherrpc.EvaluateListResponse, error) {
	// todo: add your logic here and delete this line
	offset := (in.Page - 1) * in.Size
	var data []mysql.Evaluate
	tx := mysql.DB.Offset(int(offset)).Limit(int(in.Size)).Order("created_at desc")
	tx.Find(&data)

	var eva []*teacherrpc.EvaluateList

	for _, datum := range data {
		list := teacherrpc.EvaluateList{
			UserId:    int64(datum.UserId),
			CollectId: int64(datum.CollectId),
			Content:   datum.Content,
		}
		eva = append(eva, &list)
	}

	return &teacherrpc.EvaluateListResponse{
		List: eva,
	}, nil
}
